<?php

/**
 * This is the model class for table "adm_user".
 *
 * The followings are the available columns in table 'adm_user':
 * @property string $id_adm_user
 * @property string $login_name
 * @property string $name
 * @property string $password
 * @property string $employee_id
 * @property string $active
 * @property string $id_adm_group
 * @property string $id_adm_company
 * @property string $id_section
 * @property string $default_id_adm_module
 * @property string $position
 * @property string $approval
 * @property integer $app_1
 * @property integer $app_2
 * @property integer $app_3
 * @property integer $app_4
 * @property integer $app_5
 * @property integer $app_6
 *
 * The followings are the available model relations:
 * @property AdmCompany $idAdmCompany
 * @property AdmGroup $idAdmGroup
 */
class AdmUser extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return AdmUser the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'adm_user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('login_name', 'required'),
			array('app_1, app_2, app_3, app_4, app_5, app_6', 'numerical', 'integerOnly'=>true),
			array('login_name, employee_id, position', 'length', 'max'=>50),
			array('name, password', 'length', 'max'=>100),
			array('active', 'length', 'max'=>1),
			array('id_adm_group, id_adm_company, id_section, default_id_adm_module, approval', 'length', 'max'=>19),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_adm_user, login_name, name, password, employee_id, active, id_adm_group, id_adm_company, id_section, default_id_adm_module, position, approval, app_1, app_2, app_3, app_4, app_5, app_6', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idAdmCompany' => array(self::BELONGS_TO, 'AdmCompany', 'id_adm_company'),
			'idAdmGroup' => array(self::BELONGS_TO, 'AdmGroup', 'id_adm_group'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_adm_user' => 'Id Adm User',
			'login_name' => 'Login Name',
			'name' => 'Name',
			'password' => 'Password',
			'employee_id' => 'Employee',
			'active' => 'Active',
			'id_adm_group' => 'Id Adm Group',
			'id_adm_company' => 'Id Adm Company',
			'id_section' => 'Id Section',
			'default_id_adm_module' => 'Default Id Adm Module',
			'position' => 'Position',
			'approval' => 'Approval',
			'app_1' => 'App 1',
			'app_2' => 'App 2',
			'app_3' => 'App 3',
			'app_4' => 'App 4',
			'app_5' => 'App 5',
			'app_6' => 'App 6',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_adm_user',$this->id_adm_user,true);
		$criteria->compare('login_name',$this->login_name,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('employee_id',$this->employee_id,true);
		$criteria->compare('active',$this->active,true);
		$criteria->compare('id_adm_group',$this->id_adm_group,true);
		$criteria->compare('id_adm_company',$this->id_adm_company,true);
		$criteria->compare('id_section',$this->id_section,true);
		$criteria->compare('default_id_adm_module',$this->default_id_adm_module,true);
		$criteria->compare('position',$this->position,true);
		$criteria->compare('approval',$this->approval,true);
		$criteria->compare('app_1',$this->app_1);
		$criteria->compare('app_2',$this->app_2);
		$criteria->compare('app_3',$this->app_3);
		$criteria->compare('app_4',$this->app_4);
		$criteria->compare('app_5',$this->app_5);
		$criteria->compare('app_6',$this->app_6);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}